<%@page import="br.com.Modelo.UsuarioCliente"%>
<%@page import="java.util.List"%>
<%@page import="br.com.Modelo.Produto"%>
<%@page import="br.com.Modelo.UsuarioComerciante"%>
<%@page import="br.com.Modelo.Pagina"%>
<%@page import="br.com.Modelo.Endereco"%>
<%@page import="br.com.Dao.UsuarioClienteDao"%>
<%@page import="br.com.Dao.UsuarioComercianteDao"%>
<%@page import="br.com.Dao.ProdutoDao"%>
<%@page import="br.com.Dao.PaginaDao"%>
<%@page import="br.com.Dao.CupomDao"%>
<%@page import="br.com.Modelo.Cupom"%>
<%@page import="br.com.Dao.EnderecoDao"%>
<%@page import="java.io.IOException"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>SB Admin - Bootstrap Admin Template</title>
<script type="text/javascript" src="/plataforma_marketing/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/plataforma_marketing/bootstrap/js/bootstrapValidator.js"></script>

    <!-- Bootstrap Core CSS -->
    <link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet">
	<link href="/plataforma_marketing/bootstrap/bootstrapValidator.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="../public/css/sb-admin.css" rel="stylesheet">

    <!-- Morris Charts CSS -->
    <link href="../public/css/plugins/morris.css" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="../public/font-awesome-4.1.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    
    
    <style>
    .btn-primary {
	color: #ffffff;
	text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
	background-color: #229ac8;
	background-image: linear-gradient(to bottom, #23a1d1, #1f90bb);
	background-repeat: repeat-x;
	border-color: #1f90bb #1f90bb #145e7a;
}

.btn-primary:hover,.btn-primary:active,.btn-primary.active,.btn-primary.disabled,.btn-primary[disabled]
	{
	background-color: #1f90bb;
	background-position: 0 -15px;
}
    
    
    </style>
</head>

<body>


	<%
		///allow access only if session exists
	    
		String[] id = (String[]) session.getAttribute("user");	    
		UsuarioCliente userCliente = null;		
		UsuarioClienteDao dao = new UsuarioClienteDao();
		
		if (id != null) {
			
			if (id[1].equals("1")) {
				userCliente = dao.validaAutenticacaoUser(
				Long.parseLong(id[0]), Integer.parseInt(id[1]));

			} else {

			}
		}
		String userName = null;
		String sessionID = null;
		
	//	out.println(userCliente.getLogin());
		
		if (userCliente != null) {
			
			Cupom cup = new Cupom();
			CupomDao cupd = new CupomDao();
			List<Cupom> cupons;
			cupons = cupd.getCupom((int)userCliente.getId());
			Cupom cupomAtual = cupd.getCupomAtivo(userCliente.getId());

	%>


  	<div id="wrapper">

		<!-- Navigation -->
		<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
		<!-- Brand and toggle get grouped for better mobile display -->
		<div class="navbar-header">
			<button type="button" class="navbar-toggle" data-toggle="collapse"
				data-target=".navbar-ex1-collapse">
				<span class="sr-only">Toggle navigation</span> <span
					class="icon-bar"></span> <span class="icon-bar"></span> <span
					class="icon-bar"></span>
			</button>
			<a class="navbar-brand" href="">Painel Administrativo</a>
		</div>
		<!-- Top Menu Items -->
		<ul class="nav navbar-right top-nav">

			<!--  if for logado -->
			<%
				//if(userComerciante != null){
			%>
			<li class="dropdown"><a class="dropdown-toggle" role="button"
				data-toggle="dropdown" href="#"> <i
					class="glyphicon glyphicon-user"></i> <%=userCliente.getLogin()%>
					<span class="caret"></span></a>
				<ul id="g-account-menu" class="dropdown-menu" role="menu">
					<li><a href="#">Meu Perfil</a></li>
					<li><a href="/plataforma_marketing/LogoutServlet"><i class="glyphicon glyphicon-lock"></i>
							Sair</a></li>
				</ul></li>
			<%
				//}
			%>



		</ul>
		<!-- Sidebar Menu Items - These collapse to the responsive navigation menu on small screens -->
		<div class="collapse navbar-collapse navbar-ex1-collapse">
			<ul class="nav navbar-nav side-nav">
				<li class="co"><a href="/plataforma_marketing"><img
						src="/plataforma_marketing/img/logo.png"></img> </a></li>

				<li class=""><a href="config_conta.jsp"><i
						class="fa fa-fw fa-file"></i> Configurações da Conta</a></li>

				<li class=""><a href="admin_cliente.jsp"><i
						class="fa fa-fw fa-file"></i> Visualizar Cupons</a></li>
			</ul>
		</div>
		<!-- /.navbar-collapse -->
</nav>
        <div id="page-wrapper">

            <div class="container-fluid" style="height: 1000px" >

                <!-- Page Heading -->
                <div class="row">        
                   

                     <div class="panel panel-default">
        <div class="panel-heading">
          <div class="panel-title">
            <i class="glyphicon glyphicon-wrench pull-right"></i>
            <h4>Configurar Conta </h4>
          </div>
        </div>
        <div class="panel-body">
        
        	        <%
				
				if(request.getParameter("check-cad")!= null){
			%>
	<div class="alert alert-danger">  
		<button type="button" class="close" data-dismiss="alert">×</button>
		<strong>Erro!</strong> <%=request.getParameter("check-cad") %>
   </div>
           <%} %>
           
           				
				<%if(request.getParameter("check-ok")!= null){%>
	<div class="alert alert-success">  
		<button type="button" class="close" data-dismiss="alert">×</button>
		<strong>OK!</strong> <%=request.getParameter("check-ok") %>
   </div>
           <%} %>
          
   
					<form id="default-form" class="form-horizontal" action="/plataforma_marketing/cliente/editar_usuario_cliente" method="post">
						<fieldset>


							<!-- Text input-->
							<div class="form-group">
								<label class="col-md-2 control-label" for="login_usuario">Nome
									de Usuário</label>
								<div class="col-md-5">
									<input id="login_empresa" name="login_user" type="text"
										placeholder="login" class="form-control input-md" value="<%=userCliente.getLogin()%>" >

								</div>
							</div>

							<!-- Password input-->
							<div class="form-group">
								<label class="col-md-2 control-label" for="senha_usuario">Senha</label>
								<div class="col-md-5">
									<input id="senha_empresa" name="senha_user" type="password"
										placeholder="" class="form-control input-md" value="<%=userCliente.getSenha() %>">

								</div>
							</div>

						

							<hr class="prettyline">
						
							<!-- Text input-->
							<div class="form-group">
								<label class="col-md-2 control-label" for="nome_usuario">Nome</label>
								<div class="col-md-5">
									<input id="nome_empresa" name="nome_user" type="text"
										placeholder="" class="form-control input-md" value="<%=userCliente.getNome() %>">

								</div>
							</div>

						

							<!-- Text input-->
							<div class="form-group">
								<label class="col-md-2 control-label" for="email_usuario">Email</label>
								<div class="col-md-5">
									<input id="cnpj" name="email_user" type="text" placeholder=""
										class="form-control input-md" value="<%=userCliente.getEmail()%>">

								</div>
							</div>
							
							
								<!-- Text input-->
							<div class="form-group">
								<label class="col-md-2 control-label" for="telefone_usuario">Telefone</label>
								<div class="col-md-5">
									<input id="cnpj" name="tel_user" type="text" placeholder=""
										class="form-control input-md" value="<%=userCliente.getTelefone()%>">

								</div>
							</div>


			<!-- Text input-->
							<div class="form-group">
								<label class="col-md-2 control-label" for="end_usuario">Endereço</label>
								<div class="col-md-5">
									<input id="cnpj" name="end_user" type="text" placeholder=""
										class="form-control input-md" value="<%=userCliente.getEnd()%>">

								</div>
							</div>
							
                                 <input type="hidden" name="id_cliente" value="<%=userCliente.getId()%>">
						
							<br />
									<hr class="prettyline">
							<!-- Button -->
							<div class="form-group" align="left">
								<label class="col-md-2 control-label" for="signin">&nbsp</label>

								<div class="col-md-5">
									<button id="signin" name="signin" class="btn btn-success">Atualizar</button>
								</div>
							</div>

						</fieldset>
					</form>
				
          
        </div><!--/panel content-->
      </div><!--/panel-->
    

  
                </div>
                <!-- /.row -->

               

            </div>
            <!-- /.container-fluid -->

        </div>
        <!-- /#page-wrapper -->

    </div>
    <!-- /#wrapper -->

    <!-- jQuery Version 1.11.0 -->
    <script src="../public/js/jquery-1.11.0.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="../public/js/bootstrap.min.js"></script>

    <!-- Morris Charts JavaScript -->

    
    <%
		}else{
	%>
    <div style="padding:10;margin:0 auto;width:80%;font-size:28;margin-top:100px; text-align:center; height : 254px; ">
      
      
     <br/> <h1> Sesssão expirada </h1> <h2>Por favor, faça o login novamente</h2>
        
       <hr> <a href="/plataforma_marketing"> <h2>Volta Inicio</h2></a>
    
    </div>

   <%} %>


  <script>

 

  $(document).ready(function() {   // Generate a simple captcha

	    $('#default-form').bootstrapValidator({
	        //live: 'disabled',
	        message: 'This value is not valid',
	        feedbackIcons: {
	            valid: 'glyphicon glyphicon-ok',
	            invalid: 'glyphicon glyphicon-remove',
	            validating: 'glyphicon glyphicon-refresh'
	        },
	        fields: {	        		          
	            login_user: {	               
	                validators: {
	                    notEmpty: {
	                        message: 'O nome de usuário é necessário e não pode ser vazio'
	                    },
	                    stringLength: {
	                        min: 6,
	                        max: 30,
	                        message: 'O nome de usuário deve ter mais de 6 e menos de 30 caracteres'
	                    },
	                    regexp: {
	                        regexp: /^[a-zA-Z0-9_\.]+$/,
	                        message: 'O nome de usuário não pode consistir de pontos, virgulas ou espaços'
	                    }
	                   
	                }
	            },senha_user: {
	                validators: {
	                    notEmpty: {
	                        message: 'A senha é necessária e não pode ser vazia'
	                    },
	                    different: {
	                        field: 'login_usuario',
	                        message: 'A senha não pode ser a mesma do nome de usuário'
	                    }
	                }
	            },
	            email_user: {
	                validators: {
	                    notEmpty: {
	                        message: 'Digite o seu email'
	                    },
	                    regexp:{
	                    	regexp: /^[a-zA-Z0-9][a-zA-Z0-9\._-]+@([a-zA-Z0-9\._-]+\.)[a-zA-Z-0-9]{2}/,
							message: 'Você deve digitar um formato de e-mail válido'
		                    }
	                }
	            },
	            end_user: {
	                validators: {
	                    notEmpty: {
	                        message: 'The gender is required'
	                    }
	                }
	            },
	            tel_user:{
					validators:{
						notEmpty:{
							message: 'Você deve digitar o número de telefone'
							},
							integer:{
								message: 'o telefone deve consistir apenas de números'
								},
								stringLength: {
			                        min: 8,
			                        max: 13,
			                        message: 'O telefone deve ter mais de 6 e menos de 13 numeros'
						}}
		            }
	          
	        }

	    });
	    $('#resetBtn').click(function() {
	        $('#default-form').data('bootstrapValidator').resetForm(true);
	    });

  }); 
</script>
</body>

</html>